package com.yunkuhui.www.demo.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

@Component
public class LogInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		System.out.println("LogInterceptor拦截器");
		System.out.println(request.getRequestURI());
		if (request.getRequestURI().equals("/demo/interceptor/0")) {
			PrintWriter writer = response.getWriter();
			writer.write("/demo/interceptor/0");
			return false;
		}
		return true;
	}
}
